//
//  MBDPersonalInfoViewModel.swift
//  
//
//  Created by kyson on 2023/6/12.
//

import Foundation
import UIKit
import Kingfisher

class MBDDetailCellModel : MBDCommonCellModel {
    var itemName : String?
    
    var detailText : String?
    var detailImageURLString : String?

    private var detailType : MBDDetailType?
    //下个页面的标题
    var modifyVCTitle : String?

    var accessable : Bool?
    var location : MBDCellLocation?
    
    var authed : Bool?
    
    func isEmpty() -> Bool {
        return detailText == MBDDetailUserNameCellModel.setUserName
    }
}

class MBDDetailAvatarCellModel : MBDDetailCellModel {
    static let setUserName = "设置头像"
    
    override func isEmpty() -> Bool {
        return detailText == MBDDetailUserNameCellModel.setUserName
    }
}

class MBDDetailUserNameCellModel : MBDDetailCellModel {
    static let setUserName = "设置用户名"
    
    override func isEmpty() -> Bool {
        return detailText == MBDDetailUserNameCellModel.setUserName
    }
}

class MBDDetailWechatNumCellModel : MBDDetailCellModel {
    
    static let setWechatNum = "设置微信号"
    
    override func isEmpty() -> Bool {
        return detailText == MBDDetailWechatNumCellModel.setWechatNum
    }
}

class MBDPersonalInfoViewModel : NSObject {
    @objc dynamic var cellModels : Array<MBDDetailCellModel>?
    var detailImage : UIImage?
    
    static func defaultCellModels(accountinfo : MBDAccountInfoModel!) -> Array<MBDDetailCellModel>{
        var cellModels = Array<MBDDetailCellModel>()
        
        let avatarCellModel = MBDDetailAvatarCellModel()
        avatarCellModel.itemName = "头像"
        avatarCellModel.location = .top
        avatarCellModel.accessable = true
        avatarCellModel.detailImageURLString = accountinfo.avatarUrl

        cellModels.append(avatarCellModel)
        
        let nameCellModel = MBDDetailUserNameCellModel()
        
        var realName : String = accountinfo.realName ?? ""        
        nameCellModel.itemName = "用户名"
        nameCellModel.location = .center
        nameCellModel.accessable = true
        nameCellModel.modifyVCTitle = MBDDetailUserNameCellModel.setUserName
        if realName.isBlank {
            nameCellModel.detailText = MBDDetailUserNameCellModel.setUserName
        } else {
            nameCellModel.detailText = realName
        }
        cellModels.append(nameCellModel)
        
        let wxNumberCellModel = MBDDetailWechatNumCellModel()
        
        let weChatNumber : String = accountinfo.weChatNumber ?? ""        
        wxNumberCellModel.itemName = "微信号"
        wxNumberCellModel.authed = accountinfo.weChatNumberOcr == accountinfo.weChatNumber
        wxNumberCellModel.modifyVCTitle = MBDDetailWechatNumCellModel.setWechatNum
        if weChatNumber.isBlank {
            wxNumberCellModel.detailText = MBDDetailWechatNumCellModel.setWechatNum
        } else {
            wxNumberCellModel.detailText = weChatNumber
        }
        nameCellModel.location = .bottom
        wxNumberCellModel.accessable = true
        cellModels.append(wxNumberCellModel)
        
        return cellModels
    }
    
}
